package com.doudou.dubbo.demo.service;

import com.doudou.dubbo.demo.api.GreetingService;
import com.doudou.dubbo.demo.po.Pojo;
import com.doudou.dubbo.demo.po.Result;
import java.io.IOException;
import org.apache.dubbo.common.json.JSON;
import org.apache.dubbo.rpc.RpcContext;

/**
 * @author zhaozw
 * @version 1.0
 * @date 2025-07-10 20:13
 **/
public class GreetingServiceImpl implements GreetingService {

    @Override
    public String sayHello(String name) {
        try {
            Thread.sleep(1000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return "Hello " + name + " " + RpcContext.getContext()
                .getAttachment("company");
    }

    @Override
    public Result<String> testGeneric(Pojo pojo) {
        Result<String> result = new Result<>();
        result.setSuccess(true);
        try {
            result.setData(JSON.json(pojo));
        } catch (IOException e) {
            e.printStackTrace();
        }
        return result;
    }
}
